#include "tinyxml.h"

#include "mainDAE.h"
#include "GeoDAE.h"
using namespace MaEngine;


void xmlDaeParseGeometries::parse( GeometryList &geometryList)
{
//cout <<"file:"<<__FILE__<<" line:"<<__LINE__ <<endl;
	geometryList.clear();
	if( NULL == m_Node )
	{
		return;
	}
	TiXmlNode *pre,*ir;
	ir = pre= m_Node->FirstChild("geometry");
//cout <<"file:"<<__FILE__<<" line:"<<__LINE__ <<endl;
	while( NULL != ir)
	{
		TiXmlElement* element = ir->ToElement();
		const char *id = element->Attribute("id");
		const char *name = element->Attribute("name");
cout <<"file:"<<__FILE__<<" line:"<<__LINE__<<"id="<<id<<",name="<<name<<endl;
		Geometry geoNode(id,name);
		this->parseMesh(ir,geoNode);
		
		geometryList.push_back(geoNode);


		ir = m_Node->IterateChildren(pre);
		pre = ir;
	};
//cout <<"file:"<<__FILE__<<" line:"<<__LINE__ <<endl;
}
void xmlDaeParseGeometries::parseMesh( TiXmlNode * node, Geometry &geo )
{
//cout <<"file:"<<__FILE__<<" line:"<<__LINE__ <<endl;
	if( NULL == node )
	{
		return;
	}
	TiXmlNode *pre,*ir;
	ir = pre= node->FirstChild("mesh");
	while( NULL != ir)
	{
		TiXmlElement* element = ir->ToElement();

		this->parseSource(ir,geo);
		this->parseVertices(ir,geo);
		this->parseTriangles(ir,geo);

		ir = node->IterateChildren("mesh",pre);
		pre = ir;
	};
//cout <<"file:"<<__FILE__<<" line:"<<__LINE__ <<endl;

}
void xmlDaeParseGeometries::parseSource( TiXmlNode * node, Geometry &geo )
{
//cout <<"file:"<<__FILE__<<" line:"<<__LINE__ <<endl;
	if( NULL == node )
	{
		return;
	}
	TiXmlNode *pre,*ir;
	ir = pre= node->FirstChild("source");
	while( NULL != ir)
	{
		TiXmlElement* element = ir->ToElement();

		const char *id = element->Attribute("id");
cout <<"file:"<<__FILE__<<" line:"<<__LINE__<<"id="<<id<<endl;


		ir = node->IterateChildren("source",pre);
		pre = ir;
	};
//cout <<"file:"<<__FILE__<<" line:"<<__LINE__ <<endl;

}

void xmlDaeParseGeometries::parseVertices( TiXmlNode * node, Geometry &geo )
{

}

void xmlDaeParseGeometries::parseTriangles( TiXmlNode * node, Geometry &geo )
{

}

